package com.jiexinyun.ftp;

import org.apache.commons.net.ftp.FTPSClient;

import java.io.IOException;

public class FTPSClient2 {

    public static void main(String[] args) throws Exception {
        FTPSClient ftpClient = new FTPSClient();
        try {
            // 1. 连接
            ftpClient.connect("192.168.0.101", 21);
            System.out.println("连接状态: " + ftpClient.isConnected());
            System.out.println("连接响应: " + ftpClient.getReplyString());

            // 2. 登录
            boolean isLogin = ftpClient.login("test1", "123456");
            System.out.println("登录结果: " + isLogin);
            System.out.println("登录响应: " + ftpClient.getReplyString());

            if (!isLogin) {
                // 尝试其他认证方式（如匿名登录测试）
                boolean isAnonymous = ftpClient.login("anonymous", "");
                System.out.println("匿名登录结果: " + isAnonymous);
                System.out.println("匿名登录响应: " + ftpClient.getReplyString());
            }

        } catch (IOException e) {
            System.err.println("操作异常: " + e.getMessage());
        } finally {
            try {
                if (ftpClient.isConnected()) ftpClient.disconnect();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
